﻿using System;

namespace Database
{
    public class Pass
    {
        public string Number { get; private set; }

        private DateTime _issueDate;
        private readonly bool _isBlocked;
        private readonly bool _isTemporary;
        private readonly string _dorm;

        public Pass(bool isTemporary, string dorm)
        {
            Number = NextNumber();
            _issueDate = DateTime.Now;
            _isBlocked = false;
            _isTemporary = isTemporary;
            _dorm = dorm;
        }

        // for database loading
        public Pass(DateTime issueDate, bool isTemporary, bool isBlocked, string dorm, string number)
        {
            _issueDate = issueDate;
            _isTemporary = isTemporary;
            _isBlocked = isBlocked;
            _dorm = dorm;
            Number = number;
        }

        public string GetSqlData()
        {
            return "'" + Number + "', " +
                   "'" + _issueDate.ToShortDateString() + "', " +
                   (_isBlocked ? 1 : 0) + ", " +
                   (_isTemporary ? 1 : 0) + ", " +
                   "'" + _dorm + "'";
        }

        public string GetPassType()
        {
            return _isTemporary ? "временный" : "постоянный";
        }

        public bool GetPermission()
        {
            return !_isBlocked;
        }

        public string GetDorm()
        {
            return _dorm;
        }

        public string GetIssueDate()
        {
            return _issueDate.ToShortDateString();
        }
        
        private static string NextNumber()
        {
            var r = new Random();
            return r.Next(100) + "-" + r.Next(1000);
        }
    }
}
